package supermarket;
import java.util.Scanner;

public class supermarticket {
    public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
        Goods[] goodses = new Goods[3];
        for (int i = 0; i < goodses.length; i++) {
            goodses[i] = new Goods();
            System.out.print("请录入第" + (i + 1) + "件商品的名称:");
            goodses[i].setGoodsName(scan.next());
            System.out.print("请录入第" + (i + 1) + "件商品的数量:");
            goodses[i].setGoodsQuantity(scan.nextInt());
            System.out.print("请录入第" + (i + 1) + "件商品的单价:");
            goodses[i].setGoodsPrice(scan.nextDouble());
            System.out.println("第" + (i + 1) + "件商品录入成功");
        }
        
        
        

        System.out.println("***欢迎来到旺旺超市***");
        System.out.println("--------------------------");
        System.out.println("商品名称       数量        单价         金额");
        for (int i = 0; i < goodses.length; i++) {
            System.out.println(goodses[i].getGoodsName() + "         " + goodses[i].getGoodsQuantity() + "         "
                    + goodses[i].getGoodsPrice() + "         " + goodses[i].getGoodsSubtotal());
        }

        System.out.println("--------------------------");


        int totalQuantity = 0;
        double totalAmount = 0.0;
        for (int i = 0; i < goodses.length; i++) {
            totalQuantity += goodses[i].getGoodsQuantity();
            totalAmount += goodses[i].getGoodsSubtotal();
        }
        System.out.println("总数量:" + totalQuantity);
        System.out.println("总金额:" + totalAmount);

        //4.购买总数量超过10件或者总金额大于100,就在总价的基础上打五折
        //||
        double discountAmount = (totalQuantity > 10 || totalAmount > 100) ? totalAmount * 0.5 : totalAmount;
        System.out.println("已优惠金额:" + (totalAmount - discountAmount));//已优惠金额=总金额-实付金额
        System.out.println("实付金额:" + discountAmount);

    }
}
